<template>
  <div class="header">
    <div class="left">
      <span class="left-btn" @click="handleClick">首页</span>
    </div>
    <div class="center">
      <div class="center-title">可视化大数据</div>
    </div>
    <div class="right">
      <span class="right-btn">统计报告</span>
      <span class="right-time">{{ time }}</span>
    </div>
  </div>
</template>

<script setup lang="js">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'
import moment from 'moment'

const $router = useRouter()
const time = ref(moment().format('YYYY-MM-DD hh:mm:ss'))
const timer = ref(0)

function handleClick() {
  $router.push('/home')
}

onMounted(() => {
  timer.value = setInterval(() => {
    time.value = moment().format('YYYY-MM-DD hh:mm:ss')
  }, 1000);
})

onBeforeUnmount(() => {
  clearInterval(timer.value)
})
</script>

<style scoped lang="scss">
.header {
  width: 100%;
  height: 50px;
  display: flex;

  .left {
    flex: 1.5;
    background: url("../../images/screen-header-left-bg.png") no-repeat;
    background-size: cover;

    .left-btn {
      float: right;
      text-align: center;
      line-height: 50px;
      color: #29fcff;
      font-size: 20px;
      width: 130px;
      height: 50px;
      background: url("../../images/screen-header-btn-bg-l.png") no-repeat;
      background-size: 100% 100%;
    }
  }

  .center {
    flex: 2;

    .center-title {
      text-align: center;
      line-height: 75px;
      color: #29fcff;
      font-size: 30px;
      width: 100%;
      height: 75px;
      background: url("../../images/screen-header-center-bg.png") no-repeat;
      background-size: 100% 100%;
    }
  }

  .right {
    flex: 1.5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: url("../../images/screen-header-right-bg.png") no-repeat;
    background-size: cover;

    .right-btn {
      float: left;
      text-align: center;
      line-height: 50px;
      color: #29fcff;
      font-size: 20px;
      width: 130px;
      height: 50px;
      background: url("../../images/screen-header-btn-bg-r.png") no-repeat;
      background-size: 100% 100%;
    }

    .right-time {
      line-height: 50px;
      margin-right: 15px;
      color: #29fcff;
      font-size: 20px;
    }
  }
}
</style>